package com.woniuxy.stage3demo.service.kang.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.kang.FraudEngineBean;
import com.woniuxy.stage3demo.mapper.kang.FraudEngineMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.kang.IFraudEngineService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Transactional(readOnly = true)
public class FraudEngineServiceImpl implements IFraudEngineService {

    @Resource
    private FraudEngineMapper fraudEngineMapper;

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public int addFraudEngine(FraudEngineBean fraudEngineBean) {
        fraudEngineBean.setFraudNo(new SimpleDateFormat("yyMMddHHmmssssss").format(new Date()));
        return fraudEngineMapper.addFraudEngine(fraudEngineBean);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public int delFraudEngine(Long id) {
        return fraudEngineMapper.delFraudEngine(id);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public int modFraudEngine(FraudEngineBean fraudEngineBean) {
        return fraudEngineMapper.modFraudEngine(fraudEngineBean);
    }

    @Override
    public PageInfo<FraudEngineBean> findLimit(PageRequest pageRequest,FraudEngineBean fraudEngineBean) {
        return PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getLimit()).doSelectPageInfo(()->fraudEngineMapper.findLimit(pageRequest,fraudEngineBean));
    }
}
